/**     
 * @Title: MyApplication.java   
 * @Package com.yitong   
 * @Description: TODO
 * @author weiwei 
 * @date 2017年7月20日 上午11:08:09   
 * @version V1.0     
 */
package com.yitong;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.web.servlet.ErrorPage;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.HttpMessageConverter;

import com.yitong.spring.FastJsonHttpMessageConverter;

/**
 * @ClassName: MyApplication
 * @Description: spring boot详细见文档
 *               http://docs.spring.io/spring-boot/docs/1.5.4.RELEASE/reference/htmlsingle/
 * @author weiwei
 * @date 2017年7月20日 上午11:08:09
 * 
 */
@SpringBootApplication
public class MyApplication {

	/**
	 * @Title: fastJsonHttpMessageConverters
	 * @Description: 返回json处理
	 * @Reutrn HttpMessageConverters
	 */
	@Bean
	public HttpMessageConverters fastJsonHttpMessageConverters() {
		// 自定义
		FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
		HttpMessageConverter<?> converter = fastConverter;
		return new HttpMessageConverters(converter);
	}

	/**
	 * @Title: containerCustomizer
	 * @Description: 指定返回错误页面，详细见：
	 *               https://www.sporcic.org/2014/05/custom-error-pages-with-spring-boot/
	 * @Reutrn EmbeddedServletContainerCustomizer
	 */
	@Bean
	public EmbeddedServletContainerCustomizer containerCustomizer() {
		return new EmbeddedServletContainerCustomizer() {
			@Override
			public void customize(ConfigurableEmbeddedServletContainer container) {
				ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED, "/401.html");
				ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/404.html");
				ErrorPage error405Page = new ErrorPage(HttpStatus.METHOD_NOT_ALLOWED, "/405.html");
				ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500.html");
				container.addErrorPages(error401Page, error404Page, error405Page, error500Page);
			}
		};
	}

	/**
	 * @Title: main
	 * @Description: TODO
	 * @param args
	 * @Reutrn void
	 */
	public static void main(String[] args) {
		SpringApplication.run(MyApplication.class, args);
	}
}
